USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedAttributes_ChangeOrder]    Script Date: 05/25/2011 06:59:25 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [classified].[ClassifiedAttributes_ChangeOrder]
	@CategoryID bigint,
	@PrevAttributeID bigint,
	@NextAttributeID bigint
AS
BEGIN
	SET NOCOUNT ON;
	
	BEGIN TRY
	
		BEGIN TRANSACTION TR
			DECLARE @posFirst tinyint;
			DECLARE @posSecond tinyint;
			
			SELECT @posFirst = SortOrder FROM classified.ClassifiedAttributes 
				WHERE CategoryID = @CategoryID AND AttributeID = @PrevAttributeID
			SELECT @posSecond = SortOrder FROM classified.ClassifiedAttributes 
				WHERE CategoryID = @CategoryID AND AttributeID = @NextAttributeID
			
			
			
			UPDATE classified.ClassifiedAttributes
			SET SortOrder = @posSecond
			WHERE CategoryID = @CategoryID AND AttributeID = @PrevAttributeID
			
			UPDATE classified.ClassifiedAttributes
			SET SortOrder = @posFirst
			WHERE CategoryID = @CategoryID AND AttributeID = @NextAttributeID

		COMMIT TRANSACTION TR
    END TRY
    BEGIN CATCH
		ROLLBACK TRANSACTION TR
    END CATCH
END








GO


